package com.syp.lease.web.app.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.syp.lease.model.entity.ViewAppointment;
import com.syp.lease.web.app.mapper.GraphInfoMapper;
import com.syp.lease.web.app.mapper.LabelInfoMapper;
import com.syp.lease.web.app.mapper.RoomInfoMapper;
import com.syp.lease.web.app.mapper.ViewAppointmentMapper;
import com.syp.lease.web.app.service.ApartmentInfoService;
import com.syp.lease.web.app.service.ViewAppointmentService;
import com.syp.lease.web.app.vo.apartment.ApartmentItemVo;
import com.syp.lease.web.app.vo.appointment.AppointmentDetailVo;
import com.syp.lease.web.app.vo.appointment.AppointmentItemVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class ViewAppointmentServiceImpl extends ServiceImpl<ViewAppointmentMapper, ViewAppointment>
        implements ViewAppointmentService {

    // 注入公寓信息服务
    @Autowired
    private ApartmentInfoService apartmentInfoService;
    // 注入标签信息Mapper
    @Autowired
    private LabelInfoMapper labelInfoMapper;
    // 注入图表信息Mapper
    @Autowired
    private GraphInfoMapper graphInfoMapper;
    // 注入房间信息Mapper
    @Autowired
    private RoomInfoMapper roomInfoMapper;

    /**
     * 根据用户ID列出预约看房项目
     *
     * @param userId 用户ID
     * @return 预约看房项目列表
     */
    @Override
    public List<AppointmentItemVo> listItemByUserId(Long userId) {
        return baseMapper.listItemByUserId(userId);
    }

    /**
     * 根据ID获取预约看房详情
     *
     * @param id 预约看房记录ID
     * @return 预约看房详情对象
     */
    @Override
    public AppointmentDetailVo getDetailById(Long id) {
        // 通过ID查询预约看房信息
        ViewAppointment viewAppointment = baseMapper.selectById(id);
        // 根据预约看房记录中的公寓ID查询公寓信息
        ApartmentItemVo apartmentItemVo = apartmentInfoService.selectApartmentItemVoById(viewAppointment.getApartmentId());
        // 创建预约看房详情对象
        AppointmentDetailVo appointmentDetailVo = new AppointmentDetailVo();
        // 将预约看房信息复制到详情对象中
        BeanUtils.copyProperties(viewAppointment, appointmentDetailVo);
        // 设置公寓信息到详情对象中
        appointmentDetailVo.setApartmentItemVo(apartmentItemVo);
        return appointmentDetailVo;
    }
}
